//
//  KFDFAQCellContentComposer.m
//  KFD
//
//  Created by JIRENTIANXIANG on 7/7/15.
//  Copyright © 2015 kfd. All rights reserved.
//

#import "KFDFAQCellContentComposer.h"
#import "ui_config.h"
#import "JRTXLinearLayout.h"

@interface KFDFAQCellContentComposer ()

@property (strong,nonatomic) UILabel* questionLabel;
@property (strong,nonatomic) UILabel* answerLabel;

@end

@implementation KFDFAQCellContentComposer

-(instancetype)init
{
    if (self=[super init]) {
        _view=[[UIView alloc] init];
        [self setupQuestionLabel];
        [self setupAnswerLabel];
    }
    return self;
}

-(void)setFaq:(KFDFaq *)faq
{
    _faq=faq;
    self.questionLabel.text=faq.title;
    self.answerLabel.text=faq.content;
}

-(void)setupQuestionLabel
{
    self.questionLabel=[[UILabel alloc] init];
    self.questionLabel.font=[UIFont systemFontOfSize:16];
    self.questionLabel.textColor=KFD_TEXT_DARK_GRAY;
}

-(void)setupAnswerLabel
{
    self.answerLabel=[[UILabel alloc] init];
    self.answerLabel.font=[UIFont systemFontOfSize:14];
    self.answerLabel.textColor=KFD_TEXT_DARK_GRAY;
}

-(CGFloat)layout
{
    JRTXLinearLayout* questionLayout=[[JRTXLinearLayout alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-20-20-20, 0)];
    [questionLayout appendLabel:self.questionLabel widthLimit:SCREEN_WIDTH-20-20-20 alignment:JRTXLinearLayoutAlignmentLeft];
    UIView* questionContainer=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-20, 40)];
    UIImageView* questionIcon=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    questionIcon.image=[UIImage imageNamed:@"issue-box"];
    [questionContainer addSubview:questionIcon];
    UILabel* questionCharacter=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
    questionCharacter.text=@"问";
    questionCharacter.textColor=KFD_WHITE;
    questionCharacter.font=[UIFont systemFontOfSize:15];
    questionCharacter.textAlignment=NSTextAlignmentCenter;
    questionCharacter.center=questionIcon.center;
    [questionContainer addSubview:questionCharacter];
    
    [questionContainer addSubview:questionLayout.view];
    JRTXLinearLayout* layout=[[JRTXLinearLayout alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH-20-20, 0)];
    [layout appendBlankLineWithHeight:15];
    [layout appendView:questionContainer alignment:JRTXLinearLayoutAlignmentLeft];
    [layout appendLabel:self.answerLabel widthLimit:SCREEN_WIDTH-20-20 alignment:JRTXLinearLayoutAlignmentLeft];
    [layout appendBlankLineWithHeight:15];
    [self.view addSubview:layout.view];
    return layout.view.frame.size.height;
}

@end
